package com.jhgsys.internal.peccancy.service.impl;

import com.jhgsys.internal.peccancy.entity.PeccancyClauseRuleRecord;
import com.jhgsys.internal.peccancy.mapper.PeccancyClauseRuleRecordMapper;
import com.jhgsys.internal.peccancy.service.IPeccancyClauseRuleRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 奖惩规则变更记录 Service实现
 *
 * @author admin
 * @date 2024-08-08 13:20:30
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PeccancyClauseRuleRecordServiceImpl extends ServiceImpl<PeccancyClauseRuleRecordMapper, PeccancyClauseRuleRecord> implements IPeccancyClauseRuleRecordService {

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-08-08 13:20:30
     * @param request QueryRequest
     * @param peccancyClauseRuleRecord peccancyClauseRuleRecord
     * @return IPage<PeccancyClauseRuleRecord>
    */
    @Override
    public IPage<PeccancyClauseRuleRecord> findPeccancyClauseRuleRecordPage(QueryRequest request, PeccancyClauseRuleRecord peccancyClauseRuleRecord) {
        LambdaQueryWrapper<PeccancyClauseRuleRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PeccancyClauseRuleRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<PeccancyClauseRuleRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author admin
     * @date 2024-08-08 13:20:30
     * @param peccancyClauseRuleRecord peccancyClauseRuleRecord
     * @return List<PeccancyClauseRuleRecord>
     */
    @Override
    public List<PeccancyClauseRuleRecord> findPeccancyClauseRuleRecords(PeccancyClauseRuleRecord peccancyClauseRuleRecord) {
	    LambdaQueryWrapper<PeccancyClauseRuleRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PeccancyClauseRuleRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author admin
    * @date 2024-08-08 13:20:30
    * @param id
    * @return PeccancyClauseRuleRecord
    */
    @Override
    public PeccancyClauseRuleRecord findPeccancyClauseRuleRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author admin
     * @date 2024-08-08 13:20:30
     * @param peccancyClauseRuleRecord peccancyClauseRuleRecord
     */
    @Override
    @Transactional
    public void createPeccancyClauseRuleRecord(PeccancyClauseRuleRecord peccancyClauseRuleRecord) {
        peccancyClauseRuleRecord.setCreatedTime(new Date());
        this.save(peccancyClauseRuleRecord);
    }

    /**
     * 修改
     * @author admin
     * @date 2024-08-08 13:20:30
     * @param peccancyClauseRuleRecord peccancyClauseRuleRecord
     */
    @Override
    @Transactional
    public void updatePeccancyClauseRuleRecord(PeccancyClauseRuleRecord peccancyClauseRuleRecord) {
        peccancyClauseRuleRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(peccancyClauseRuleRecord);
    }

    /**
     * 逻辑删除
     * @author admin
     * @date 2024-08-08 13:20:30
     * @param peccancyClauseRuleRecord peccancyClauseRuleRecord
     * @param peccancyClauseRuleRecordIds peccancyClauseRuleRecordIds
     */
    @Override
    @Transactional
    public void deletePeccancyClauseRuleRecord(PeccancyClauseRuleRecord peccancyClauseRuleRecord,String peccancyClauseRuleRecordIds) {
        List<String> list = Arrays.asList(peccancyClauseRuleRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(peccancyClauseRuleRecord,new LambdaQueryWrapper<PeccancyClauseRuleRecord>().in(PeccancyClauseRuleRecord::getClauseRuleRecordId,list));
	}

    /**
    * 物理删除
    * @author admin
    * @date 2024-08-08 13:20:30
    * @param peccancyClauseRuleRecordIds peccancyClauseRuleRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeletePeccancyClauseRuleRecord(String peccancyClauseRuleRecordIds) {
        List<String> list = Arrays.asList(peccancyClauseRuleRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<PeccancyClauseRuleRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(PeccancyClauseRuleRecord::getClauseRuleRecordId,list);
        this.remove(wapper);
    }
}
